Namespace OpenArchive
    Namespace Document
        Namespace Components
            Public Class ImageComponent
                Inherits Component
                Private Const c_ComponentName As String = "Image"
                Private m_Version As New Version(1, 0)
                Friend Sub New(ByVal Image As Byte())
                    Initialize()
                    Content = Image
                    Dim _mts As New MimeTypes()
                    'MimeType = _mts(Drawing.Image.FromStream(New Global.System.IO.MemoryStream(TryCast(DataObjects.Content, Byte()))).RawFormat.ToString())
                End Sub
                Friend Sub New(ByVal Image As Byte(), ByVal Mimetype As String)
                    Initialize()
                    Content = Image
                    'MyBase.MimeType = Mimetype
                End Sub
                Friend Sub New(ByVal ImagecomponentDatafromDatabase As Data.ImageComponentData)
                    If m_Version.CompareTo(ImagecomponentDatafromDatabase.Version) < 0 Then
                        Throw New VersionconflictException()
                    End If
                    DataObjects = ImagecomponentDatafromDatabase
                End Sub
                Private Sub Initialize()
                    MyBase.SetComponentName(c_ComponentName)
                    DataObjects = New Data.ImageComponentData()
                    Version = m_Version
                End Sub
                Public Shadows Property Content() As Byte()
                    Get
                        Return TryCast(MyBase.Content, Byte())
                    End Get
                    Set(ByVal value As Byte())
                        MyBase.Content = value
                    End Set
                End Property
                Friend Function GetImage() As Drawing.Image
                    Return Drawing.Image.FromStream(New Global.System.IO.MemoryStream(TryCast(Content, Byte())))
                End Function
                Friend ReadOnly Property Pages() As Integer
                    Get
                        Return Drawing.Image.FromStream(New Global.System.IO.MemoryStream(TryCast(DataObjects.Content, Byte()))).GetFrameCount(Drawing.Imaging.FrameDimension.Page)
                    End Get
                End Property
                Friend Property Created() As DateTime
                    Get
                        Return TryCast(DataObjects, Data.ImageComponentData).Created
                    End Get
                    Set(ByVal value As DateTime)
                        TryCast(DataObjects, Data.ImageComponentData).Created = value
                    End Set
                End Property
                Friend Property Modified() As DateTime
                    Get
                        Return TryCast(DataObjects, Data.ImageComponentData).Modified
                    End Get
                    Set(ByVal value As DateTime)
                        TryCast(DataObjects, Data.ImageComponentData).Modified = value
                    End Set
                End Property
                Friend Overrides Function IsResponsible(ByVal ComponentDataType As Global.System.Type, ByVal Version As Version) As Object
                    Return Type.Equals(ComponentDataType, New Components.Data.ImageComponentData().GetType())
                End Function
                Public Overrides ReadOnly Property IsSingleInstanceType() As Boolean
                    Get
                        Return False ' For Multipage
                    End Get
                End Property
            End Class
        End Namespace
    End Namespace
End Namespace